<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>x-admin</title>
    <link rel="stylesheet" href="/static/xadmin/lib/layui/css/layui.css">
    <style>
    </style>
    <script>
        /^http(s*):\/\//.test(location.href) || alert('请先部署到 localhost 下再访问');
    </script>
</head>
<body>
<div class="layui-form">
    <table class="layui-table">
        <input type="hidden" id="id" value="{$find.id}">
        <tr>
            <td>
                <label class="layui-form-label">广告位名称</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <input type="text" id="name" value="{$find.name}" required  lay-verify="required" placeholder="请输入广告位名称" autocomplete="off" class="layui-input">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <label class="layui-form-label">广告位排序</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <input type="number" id="sort" value="{$find.sort}" min="0" required  lay-verify="required" placeholder="请输入广告位排序" autocomplete="off" class="layui-input">
                </div>
            </td>
        </tr>

        <tr>
            <td>
                <label class="layui-form-label">状态</label>
            </td>
            <td>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="开启" {if condition="$find.status eq 1 "}checked{/if}>
                    <input type="radio" name="status" value="2" title="关闭" {if condition="$find.status eq 2 "}checked{/if}>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center">
                <div class="layui-input-block">
                    <button class="layui-btn" onclick="add_sumbit()">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </td>
        </tr>
    </table>
</div>
<script src="/static/xadmin/lib/layui/jquery-3.2.1.min.js"></script>
<script src="/static/xadmin/lib/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/xadmin/' //静态资源所在路径
    });
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
    });

    //添加
    function add_sumbit() {
        var id=$("#id").val();
        var name=$("#name").val();
        var sort=$("#sort").val();
        var status = $('input[name=status]:checked').val();
        $.post(
            "{:url('admin/adsposition/edit')}",
            {id:id,name:name,status:status,sort:sort},
            function (data) {
                console.log(data);
                if(data.code==1){
                    layer.msg(data.msg,{icon:1});
                    setTimeout(function () {
                        parent.layer.closeAll();
                        parent.location.reload();
                    },1500);
                }else{
                    layer.msg(data.msg,{icon:2});
                }
            });

    }
</script>
</body>
</html>
